package cn.orange.controller;
import cn.orange.User;
import cn.orange.feign.UserService;
import cn.orange.sentinel.BlockDemote;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class OrderController {


    @Autowired
    private UserService userService;
    @GetMapping("order/{id}")
    //Sentinel限流策略
    @SentinelResource(value = "getUserById",blockHandler = "demoteMethod",blockHandlerClass = BlockDemote.class,fallback = "fusingGetUserByIdMethod")
    public User getUserById(@PathVariable("id") Long id){
//        int a = 1/0;
        return userService.getById(id);
    }
    //sentinel熔断策略适用于自己
    public User fusingGetUserByIdMethod(@PathVariable("id") Long id,Throwable throwable){
        return new User(-1L,"熔断了","请稍后重试！!!!!!!");
    }


}
